package com.mebs.edi.model.edi;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;

import com.mebs.edi.model.dom.DomAttribute;
import com.mebs.edi.model.dom.DomEntity;
import com.mebs.model.logistics.Transportation;

/**
 * 
 * ST section common for 211 and 214 files
 * 
 * @author nit
 *
 */
@Entity()
@Inheritance(strategy = InheritanceType.JOINED)
@Table(name = "edi_st")
@PrimaryKeyJoinColumn(name = "Id")
@DomEntity(name = "ST")
public abstract class EdiSt {
	@Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "Id")
	private Long id;
	
	@Column(nullable = true)
	@DomAttribute
	private Short st01; 		// Transaction Set Identifier Code
	
	@Column(nullable = true)
	@DomAttribute
	private Long st02; 			// Transaction Set Control Number
	
	@Column(nullable = true)
	@DomAttribute
	private Long se01; 			// Number of included segments
	
	@Column(nullable = true)
	@DomAttribute
	private Long se02; 			// Transaction Set Control Number
	
	@ManyToOne(cascade = CascadeType.ALL, optional = false)
    @JoinColumn(name = "transportation_id")
	private Transportation transportation;
	
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}
	
	public Short getSt01() {
		return st01;
	}

	public void setSt01(Short st01) {
		this.st01 = st01;
	}

	public Long getSt02() {
		return st02;
	}

	public void setSt02(Long st02) {
		this.st02 = st02;
	}

	public Long getSe01() {
		return se01;
	}

	public void setSe01(Long se01) {
		this.se01 = se01;
	}

	public Long getSe02() {
		return se02;
	}

	public void setSe02(Long se02) {
		this.se02 = se02;
	}
	
	public Transportation getTransportation() {
		return transportation;
	}

	public void setTransportation(Transportation transportation) {
		this.transportation = transportation;
	}

	@Override
	public String toString() {
		return "EdiSt [id=" + id + ", st01=" + st01 + ", st02=" + st02 + ", se01=" + se01 + ", se02=" + se02
				+ "]";
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result + ((se01 == null) ? 0 : se01.hashCode());
		result = prime * result + ((se02 == null) ? 0 : se02.hashCode());
		result = prime * result + ((st01 == null) ? 0 : st01.hashCode());
		result = prime * result + ((st02 == null) ? 0 : st02.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		EdiSt other = (EdiSt) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (se01 == null) {
			if (other.se01 != null)
				return false;
		} else if (!se01.equals(other.se01))
			return false;
		if (se02 == null) {
			if (other.se02 != null)
				return false;
		} else if (!se02.equals(other.se02))
			return false;
		if (st01 == null) {
			if (other.st01 != null)
				return false;
		} else if (!st01.equals(other.st01))
			return false;
		if (st02 == null) {
			if (other.st02 != null)
				return false;
		} else if (!st02.equals(other.st02))
			return false;
		return true;
	}
}
